package com.youdianda.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youdianda.dto.ArticleDto;
import com.youdianda.entity.YddArticle;
import com.youdianda.vo.*;
import com.youdianda.entity.Article;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author mosen
 * @since 2023-05-15
 */
public interface YJJddArticleMapper extends BaseMapper<YddArticle> {

    /**
     * 查看创建时间
     * @return
     */
    @Select("SELECT create_date FROM ydd_article ")
    List<YddArticle> getCreateCount();

    /**
     * 查看是置顶又是推荐并且多表查询cateid
     * @return
     */
    @Select("SELECT * FROM ydd_article a LEFT OUTER JOIN ydd_cate b ON a.`cateid`= b.`id` WHERE istop=1 AND ishot=1 ")
    List<ArticleVo> getHot();



    /**
     * 查询最新发表的文章并且分页
     * @return
     */
    @Select("SELECT * FROM ydd_article a LEFT OUTER JOIN ydd_cate b ON a.`cateid`= b.`id`  ORDER BY a.`create_date`  DESC LIMIT 1,6")
    List<ArticleHotVo> getArticleNew();

    /**
     * 查询推荐文章
     * @return
     */
    @Select("SELECT a.id,title,catename,lovenum,pic ,click FROM ydd_article a LEFT OUTER JOIN ydd_cate b ON a.`cateid`= b.`id` WHERE istop=1 AND ishot=1 ")
    List<ArticleHotVo> getArticleHot();

    /**
     * 查询文章的上一页和下一页
     * @param id
     * @return
     */
    @Select("SELECT title FROM ydd_article WHERE id =#{id}")
    List<IdVo> selectNextIdVo(Integer id);
    @Select("SELECT title FROM ydd_article WHERE id =#{id}")
    List<IdVo> selectPrevIdVo(Integer id);


    @Select("SELECT  a.id,cateid,catename,pic,title  FROM ydd_cate a RIGHT JOIN ydd_article b ON a.`id` = b.`cateid`  WHERE cateid=#{cateid}")
    List<RecommendVo> selectRecommend(Integer cateId);

    @Select("SELECT * FROM ydd_article a LEFT OUTER JOIN ydd_cate b ON a.`cateid`= b.`id` where cateid=#{id} ")
    List<ArticleVo> findBypage(Page<YddArticle> articlePageVoPage, int id);
}
